home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-30 | 4.6 KB | 170 lines | [TEXT/CWIE] |
- /********************************************************************************\
- LHiResPrintout - A subclass of LPrintout that prints at the printer's resolution
- Dan Crevier - 6/19/97 <mailto:Dan.Crevier@pobox.com>
-
- Use an LHiResPrinter instaed of LPrintout, and then call SetMaxResolution to
- print at the printer's maximum resolution.
-
- You can use GetResolution to get the printer's resolution in DPI
-
- You will probably need to move and resize the contained views to reflect the
- resolution change. One way to do this is with my LProportionalSizer class,
- released separately to the PP archives
-
- Note: text will not be automatically be resized. I've included an LHiResCaption
- class for captions that will resize the text when enclosed in a LHiResPrintout
-
- This code is based on something Greg Payne did for TCL
- Thanks to John C. Daub for lots of useful suggestions
-
- \********************************************************************************/
-
- #include "LHiResPrintout.h"
- #include <UPrintingMgr.h>
- #include <LCommander.h>
- #include <UReanimator.h>
-
- // ---------------------------------------------------------------------------
- // • CreatePrintout [static]
- // ---------------------------------------------------------------------------
- // Return a new Printout object (and its SubPanes) from the data in
- // a 'PPob' resource
-
- LHiResPrintout*
- LHiResPrintout::CreatePrintout(
- ResIDT inPrintoutID)
- {
- LCommander::SetDefaultCommander(nil);
- LHiResPrintout *thePrintout =
- (LHiResPrintout*) UReanimator::ReadObjects('PPob', inPrintoutID);
- thePrintout->FinishCreate();
- thePrintout->mDPI = 72;
-
- return thePrintout;
- }
-
- // ---------------------------------------------------------------------------
- // • LHiResPrintout
- // ---------------------------------------------------------------------------
- // Default Constructor
-
- LHiResPrintout::LHiResPrintout()
- : LPrintout()
- {
- mDPI = 72;
- }
-
-
- // ---------------------------------------------------------------------------
- // • LHiResPrintout(THPrint)
- // ---------------------------------------------------------------------------
- // Construct a Printout from an existing PrintRecord
-
- LHiResPrintout::LHiResPrintout(
- THPrint inPrintRecordH)
- : LPrintout(inPrintRecordH), mDPI(72)
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • LHiResPrintout
- // ---------------------------------------------------------------------------
- // Construct a Printout from the data in a Stream
-
- LHiResPrintout::LHiResPrintout(
- LStream *inStream)
- : LPrintout(inStream), mDPI(72)
- {
- }
-
- // ---------------------------------------------------------------------------
- // • SetMaxResolution
- // ---------------------------------------------------------------------------
- // Set the printer to its maximum square resolution
-
- void LHiResPrintout::SetMaxResolution(void)
- {
- TGetRotnBlk getRotnRec;
- short err = 0;
- Boolean hasPrGeneral;
-
- if(UPrintingMgr::OpenPrinter())
- {
- getRotnRec.iOpCode = getRotnOp;
- getRotnRec.hPrint = mPrintRecordH;
-
- ::PrGeneral((Ptr) &getRotnRec);
-
- err = ::PrError();
-
- if(err == noErr )
- {
- hasPrGeneral = true;
- }
- else
- {
- hasPrGeneral = false;
- }
- }
- UPrintingMgr::ClosePrinter();
-
- // we have PrGeneral, so we'll try to change the resolution
- if (hasPrGeneral)
- {
- Int16 maxDPI = 0, resIndex, drvrVers;
- TGetRslBlk getResRec;
- TSetRslBlk setResRec;
-
- if (UPrintingMgr::OpenPrinter())
- {
- drvrVers = ::PrDrvrVers();
-
- getResRec.iOpCode = getRslDataOp;
- ::PrGeneral((Ptr)&getResRec);
-
- if( getResRec.iError == noErr && ::PrError() == noErr )
- {
- for(resIndex = 0; resIndex < getResRec.iRslRecCnt; resIndex++ )
- {
- if( getResRec.rgRslRec[ resIndex ].iXRsl ==
- getResRec.rgRslRec[ resIndex ].iYRsl &&
- getResRec.rgRslRec[ resIndex ].iXRsl > maxDPI )
- {
- maxDPI = getResRec.rgRslRec[ resIndex ].iYRsl;
- }
- }
-
- if( maxDPI != 0 && mPrintRecordH != nil )
- {
- setResRec.iOpCode = setRslOp;
- setResRec.hPrint = mPrintRecordH;
-
- setResRec.iXRsl = maxDPI;
- setResRec.iYRsl = maxDPI;
- ::PrGeneral((Ptr)&setResRec);
- }
-
- UPrintingMgr::ClosePrinter();
-
- if( setResRec.iError == noErr && ::PrError() == noErr
- && maxDPI != 0 )
- {
- mDPI = maxDPI;
-
- // resize frame
- Rect paperRect = (**mPrintRecordH).rPaper;
-
- // Printout Frame and Image match the Paper Rectangle
-
- ResizeFrameTo(paperRect.right - paperRect.left,
- paperRect.bottom - paperRect.top, false);
- ResizeImageTo(paperRect.right - paperRect.left,
- paperRect.bottom - paperRect.top, false);
- PlaceInSuperImageAt(paperRect.left, paperRect.top, false);
- }
- }
- }
- }
- }
-